package com.sskj.b70.p.fragment;

import com.lzy.okgo.model.Response;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.R;
import com.sskj.b70.common.App;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.HaiPageBean;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.bean.TradePositionListBean;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.fragment.NewTradePositionFragment;

import java.util.ArrayList;

/**
 * Created by Lee on 2018/2/28 0028.
 */
public class NewTradePositionFragmentPst extends BasePresenter<NewTradePositionFragment> {
    public void loadData() {
        if (MyAppLication.isLogin()) {
            httpService.getBillList(3)
                    .execute(new JsonCallBack<HttpData<HaiPageBean<TradePositionListBean>>>(false) {
                        @Override
                        public void _onSuccess(Response<HttpData<HaiPageBean<TradePositionListBean>>> response) {

                            HttpData<HaiPageBean<TradePositionListBean>> httpListData = response.body();
                            if (httpListData != null) {
                                mView.updateData(httpListData.getData().getRes());
                            }
                        }

                        @Override
                        protected void _onNewsSuccess(Response<HttpData<HaiPageBean<TradePositionListBean>>> response) {
                            super._onNewsSuccess(response);
                            if (App.INSTANCE.getString(R.string.strNewTradePositionFragmentPst0).equals(response.body().getMsg())) {
                                mView.updateData(new ArrayList<>());
                            }
                        }
                    });
        }
    }

    public void pingcang(TradePositionListBean data) {
        httpService.closeLevelOrder(data.getId() + "", data.getNewPrice() + "").execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void _onSuccess(Response<HttpData> response) {
                HttpData httpListData = response.body();
                ToastUtil.showShort(httpListData.getMsg());
                if (httpListData.getStatus() == HttpConfig.STATUS_OK) {
                    mView.onPingChangSuccess(data);
                    loadData();
                }
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }
        });
    }

}
